package com.mrx.mqtt.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Map;

/**
 * @author XH.M
 * @create 2019-05-15 9:15
 */

public class IPGetter {

    @Data
    static class Model {
        private int code;
        private Page data;
    }

    @Data
    static class Page {
        private int PageNumber;
        private int TotalCount;
        private int PageSize;
        private String RequestId;
        private List<Instance> instances;
    }

    @Data
    static class Instance {
        private List<InstanceItem> Instance;
    }

    @Data
    static class InstanceItem {
        private Map<String, Object> extraProperties;
    }


    public static void main(String[] args) throws IOException {
        InputStream resourceAsStream = IPGetter.class.getClassLoader().getResourceAsStream("json.data");
        BufferedReader r = new BufferedReader(new InputStreamReader(resourceAsStream));
        String val = "";
        String l;
        while ((l = r.readLine()) != null) {
            val = val + l;
        }
        resourceAsStream.close();
        System.out.println(val);

        //or String s = FileUtils.readFileToString(new File("/.../src/main/resources/json.data"));
        ObjectMapper objectMapper = new ObjectMapper();
        Model model = objectMapper.readValue(val, Model.class);
        System.out.println(model);
    }


}